home *** CD-ROM | disk | FTP | other *** search
- /*===========================================================================*\
- || CPAINT (See Paint) Rip Toren ||
- || POB 674 ||
- || Columbia, MD 21045||
- || ||
- || Translate a file created by Microsoft (Zsoft) PcPaint into binary ||
- || image files. These files contain HP LaserJet commands for start ||
- || and stop of graphics. ||
- || ||
- || input : argv[1] = file name to process ||
- || argv[2] = flags of 'Y' and 'N' indicating which planes to ||
- || produce output for. Up to 8 planes are handled, but ||
- || EGA image has only 4. ||
- || ||
- || NOTE ! with 'C' opening 5 standard file ||
- || + 1 input file ||
- || + 8 possible planes (4 realisticaly ) ||
- || + 1 general purpose file ||
- || = 15 possible files in config.sys ||
- || ||
- \*===========================================================================*/
- #include "stdio.h"
- #include "stdlib.h"
-
- typedef unsigned char byte;
- #define min(a,b) ((a)<=(b)?(a):(b))
-
- /*--------------------------------------------------------------------*\
- | Structure definition for first 128 bytes of .PCC or .PCX file |
- \*--------------------------------------------------------------------*/
- struct header {
- byte manuf; /* manufacturer */
- byte version; /* version number */
- byte rllenc; /* run-length packing turned on */
- byte bits_p_pixel; /* bit per pixel */
- int x1,y1,x2,y2; /* cooridinated to top/left bot/rite */
- int horiz_res, vert_res; /* resolution of producing screen */
- byte palette[48]; /* beats me ??? */
- byte vmode;
- byte planes; /* number of planes in picture */
- int bytes_p_line; /* packed bytes per scan line */
- byte filler [200];
- };
-
- FILE *mppic,*mpres; /* input and output files */
- FILE *res[8]; /* a file for each possible plane */
- char buff [512];
-
- /* 0 1 2 3 4 5 6 7 */
- static char mask[8] ={ 0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
- /* names of potential outputs */
- static char *dfname[] = {"plane1.dat","plane2.dat","plane3.dat","plane4.dat",
- "plane5.dat","plane6.dat","plane7.dat","plane8.dat"};
- static char null_f[] = "NUL"; /* name for non-used planes */
-
-
- /*---------------------------------------------------------------------------*\
- | **************************** M A I N ********************************** |
- \*---------------------------------------------------------------------------*/
- main (argc,argv)
- int argc;
- char *argv[];
- {
- struct header *mp_hdr;
- unsigned char *b, c, *fb;
- int i, j, k, chr, rows,plane,bytes,bits, found_non_blank;
- long byte_cnt;
- char byte_l[5];
-
- if (argc < 2) {
- puts ("I can't read minds, how about a file name!");
- exit(1);
- }
- /*------------------------------------------------------------------------*\
- | open input file |
- \*------------------------------------------------------------------------*/
- mppic = fopen (argv[1],"rb");
- if (mppic==NULL) {
- puts ("open failed on pic file ");
- exit (1);
- }
- puts ("Open good");
-
- /*------------------------------------------------------------------------*\
- | Check for exclusion/inclusion of planes for output |
- \*------------------------------------------------------------------------*/
- if (argc >1) /* look for yes/no flags */
- {
- strupr (argv[2]); /* uppercase */
- for (i=0; *argv[2] && i<8; i++,argv[2]++)
- {
- if (*argv[2] != 'Y') dfname[i] = null_f;
- }
- }
-
- /*------------------------------------------------------------------------*\
- | get and display file header |
- \*------------------------------------------------------------------------*/
- fread (buff, 1, 128, mppic);
- mp_hdr = (struct header *) buff;
- printf ("Manufacturer = %d\n",(int) mp_hdr -> manuf );
- printf ("Version is = %d\n",(int) mp_hdr -> version );
- printf ("Run length is = %d\n",(int) mp_hdr -> rllenc );
- printf ("Bits / pixel = %d\n",(int) mp_hdr -> bits_p_pixel );
- printf ("Coordinate x1 = %d\n",(int) mp_hdr -> x1 );
- printf ("Coordinate y1 = %d\n",(int) mp_hdr -> y1 );
- printf ("Coordinate x2 = %d\n",(int) mp_hdr -> x2 );
- printf ("Coordinate y2 = %d\n",(int) mp_hdr -> y2 );
- printf ("Horizontal res = %d\n",(int) mp_hdr -> horiz_res );
- printf ("Vertical res = %d\n",(int) mp_hdr -> vert_res );
- printf ("Planes = %d\n",(int) mp_hdr -> planes );
- printf ("Bytes / line = %d\n",(int) mp_hdr -> bytes_p_line );
-
- /* allocate space for one scan line */
- fb = malloc (mp_hdr -> bytes_p_line);
-
- /*------------------------------------------------------------------------*\
- | Prime each of the files |
- \*------------------------------------------------------------------------*/
- for (i=0; i<mp_hdr -> planes; i++)
- {
- res[i] = fopen (dfname[i],"wb");
- /* set graphic for self origin */
- fprintf(res[i],"%c%s",0x1b,"*r1A");
- }
-
- byte_cnt = 0;
- found_non_blank = 0;
- /* bits per row */
- bits = (mp_hdr -> x2 - mp_hdr -> x1) + 1;
- /* row in image */
- rows = (mp_hdr -> y2 - mp_hdr -> y1) + 1;
- /* number of bytes in row (packed) */
- stci_d(byte_l, mp_hdr -> bytes_p_line);
-
- for (i=0; i<rows; i++) {
- for (plane=0; plane < mp_hdr -> planes; plane++) {
- mpres = res[plane]; /* select the file for output */
- k = bits;
- for (bytes=0; bytes < mp_hdr -> bytes_p_line; bytes++) {
- if (EOF != encget (&chr, mppic)) {
- byte_cnt ++;
- c = chr ^ 0xff; /* invert bits for HPLJ */
- /* clear last few bits if not in image*/
- if (k<8) c &= mask[k];
- *(fb+bytes) = c; /* store in save array */
- /* indicate a non-blank row */
- if (c!='\0') found_non_blank = 1;
- k -= 8; /* decrem bit count */
- if (k<0 ) k=0;
- }
- }
- if (found_non_blank)
- {
- fprintf(mpres,"%c%s%s%s",0x1b,"*b",byte_l,"W");
- for (j=0;j< mp_hdr -> bytes_p_line;j++) fputc (*(fb+j),mpres);
- }
- }
- }
- printf (" BYTE COUNT = %ld\n",byte_cnt);
-
- for (i=0; i<4; i++) {
- fprintf(res[i],"%c%s",0x1b,"*rB");
- fclose (res[i]);
- }
- fclose (mppic);
- }
-
- /*===========================================================================*\
- || Get the bytes from the file. If bits 6 & 7 are set, this is a count ||
- || of repetitions of following byte. ||
- || ||
- \*===========================================================================*/
- encget (pbyt, fid)
- int *pbyt;
- FILE *fid;
- {
- static int cnt=0, i;
- if (cnt > 0) { /* return the same byte again */
- cnt --;
- *pbyt = i;
- return (0);
- }
-
- /* no more characters */
- if (EOF== (i=fgetc(fid))) return (EOF);
-
- if (0xC0 == (0xC0 & i)) { /* it is a repeat count */
- cnt = (0x3F & i)-1;
- if (EOF == (i= fgetc(fid))) return (EOF);
- }
- *pbyt = i; /* return the byte read */
- return (0);
- }
-
-
- /*===========================================================================*\
- || trash lines ||
- || These lines were moved out , but saved for future use, ||
- \*===========================================================================*/
- /*-------------------------------------------------------------------*\
- | inner loop to produce character files, rather than binary |
- \*-------------------------------------------------------------------*/
- /* fputc (c,mpres);
- for (j=0; j<min(8,k); j++)
- if (((c << j) & 0x80) == 0) fputc ('0',mpres);
- else fputc ('1',mpres);
- k -= j; */
- /* fprintf (mpres,"%s","~\r\n"); */